home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / theLifeArk.swf / scripts / __Packages / prop / pz2.as < prev    next >
Encoding:
Text File  |  2011-09-19  |  6.4 KB  |  204 lines

  1. class prop.pz2 extends MovieClip
  2. {
  3.    var rq;
  4.    var cq;
  5.    var rStart;
  6.    var rAgl;
  7.    var c1Img;
  8.    var c2Img;
  9.    var c3Img;
  10.    var usedTimes;
  11.    var usedTimesMax;
  12.    var clockwise;
  13.    var answerR;
  14.    var answerC;
  15.    var aBtnNum;
  16.    function pz2()
  17.    {
  18.       super();
  19.       this.rq = this.cq = 3;
  20.       this.rStart = new Array();
  21.       this.rAgl = new Array();
  22.       this.c1Img = new Array();
  23.       this.c2Img = new Array();
  24.       this.c3Img = new Array();
  25.       this.usedTimes = 0;
  26.       this.usedTimesMax = 2;
  27.       this.resetMe();
  28.    }
  29.    function resetMe()
  30.    {
  31.       this.init();
  32.       this.clockwise = Math.random() * 1 <= 0.5 ? false : true;
  33.       this.answerR = Math.floor(Math.random() * 3);
  34.       this.answerC = Math.floor(Math.random() * 3);
  35.       var _loc7_ = false;
  36.       var _loc2_ = 0;
  37.       while(_loc2_ < this.rq)
  38.       {
  39.          this.rStart[_loc2_] = Math.floor(Math.random() * 4);
  40.          this.rAgl[_loc2_] = this.normalDeg(45 * Math.floor(Math.random() * 8));
  41.          this.c1Img[_loc2_] = Math.ceil(Math.random() * 3);
  42.          this.c2Img[_loc2_] = Math.ceil(Math.random() * 3);
  43.          this.c3Img[_loc2_] = Math.ceil(Math.random() * 3);
  44.          if(this.answerR != _loc2_ && !_loc7_)
  45.          {
  46.             _loc7_ = true;
  47.             var _loc6_ = Math.floor(this.cq * Math.random());
  48.             this["r" + _loc2_ + "c" + _loc6_].gotoAndStop("mask");
  49.          }
  50.          var _loc3_ = 0;
  51.          while(_loc3_ < this.cq)
  52.          {
  53.             var _loc4_ = (_loc3_ + this.rStart[_loc2_]) % 4;
  54.             this["r" + _loc2_ + "c" + _loc3_]["ctt3_" + _loc4_]._visible = true;
  55.             this["r" + _loc2_ + "c" + _loc3_]["ctt3_" + _loc4_].gotoAndStop(this.c3Img[_loc2_]);
  56.             this["r" + _loc2_ + "c" + _loc3_].ctt1.gotoAndStop(this.c1Img[_loc2_]);
  57.             this["r" + _loc2_ + "c" + _loc3_].ctt2.gotoAndStop(this.c2Img[_loc2_]);
  58.             switch(_loc3_)
  59.             {
  60.                case 0:
  61.                   this["r" + _loc2_ + "c" + _loc3_].ctt1._rotation = this.rAgl[_loc2_];
  62.                   break;
  63.                case 1:
  64.                   this["r" + _loc2_ + "c" + _loc3_].ctt1._rotation = this.normalDeg(this.rAgl[_loc2_] + 180);
  65.                   break;
  66.                case 2:
  67.                   var _loc5_ = !this.clockwise ? -1 : 1;
  68.                   this["r" + _loc2_ + "c" + _loc3_].ctt1._rotation = this.normalDeg(this.rAgl[_loc2_] + 180 + _loc5_ * 45);
  69.             }
  70.             _loc3_ = _loc3_ + 1;
  71.          }
  72.          _loc2_ = _loc2_ + 1;
  73.       }
  74.       this["r" + this.answerR + "c" + this.answerC].gotoAndStop("tar");
  75.       this.setBtns();
  76.    }
  77.    function setBtns()
  78.    {
  79.       this.aBtnNum = Math.floor(Math.random() * 4);
  80.       var _loc4_ = this.rAgl[this.answerR];
  81.       var rAgl;
  82.       switch(this.answerC)
  83.       {
  84.          case 0:
  85.             rAgl = _loc4_;
  86.             break;
  87.          case 1:
  88.             rAgl = this.normalDeg(_loc4_ + 180);
  89.             break;
  90.          case 2:
  91.             var _loc5_ = !this.clockwise ? -1 : 1;
  92.             rAgl = this.normalDeg(_loc4_ + 180 + _loc5_ * 45);
  93.       }
  94.       var _loc2_ = 0;
  95.       while(_loc2_ < 4)
  96.       {
  97.          if(_loc2_ == this.aBtnNum)
  98.          {
  99.             this["btn" + _loc2_].onPress = this.btnPrsR;
  100.             this["btn" + _loc2_].ctt1._rotation = rAgl;
  101.             this["btn" + _loc2_].ctt1.gotoAndStop(this.c1Img[this.answerR]);
  102.             this["btn" + _loc2_].ctt2.gotoAndStop(this.c2Img[this.answerR]);
  103.             var _loc3_ = 0;
  104.             while(_loc3_ < 4)
  105.             {
  106.                this["btn" + _loc2_]["ctt3_" + (this.answerC + this.rStart[this.answerR]) % 4]._visible = true;
  107.                this["btn" + _loc2_]["ctt3_" + _loc3_].gotoAndStop(this.c3Img[this.answerR]);
  108.                _loc3_ = _loc3_ + 1;
  109.             }
  110.          }
  111.          else
  112.          {
  113.             this["btn" + _loc2_].onPress = this.btnPrsW;
  114.             this["btn" + _loc2_].ctt1._rotation = this.normalDeg(rAgl + 45 + 45 * _loc2_);
  115.             this["btn" + _loc2_].ctt1.gotoAndStop(this.c1Img[this.answerR]);
  116.             this["btn" + _loc2_].ctt2.gotoAndStop(this.c2Img[this.answerR]);
  117.             _loc3_ = 0;
  118.             while(_loc3_ < 4)
  119.             {
  120.                this["btn" + _loc2_]["ctt3_" + (this.answerC + this.rStart[this.answerR] + _loc2_) % 4]._visible = true;
  121.                this["btn" + _loc2_]["ctt3_" + _loc3_].gotoAndStop(this.c3Img[this.answerR]);
  122.                _loc3_ = _loc3_ + 1;
  123.             }
  124.          }
  125.          _loc2_ = _loc2_ + 1;
  126.       }
  127.    }
  128.    function init()
  129.    {
  130.       var _loc4_ = 0;
  131.       while(_loc4_ < this.rq)
  132.       {
  133.          var _loc3_ = 0;
  134.          while(_loc3_ < this.cq)
  135.          {
  136.             this["r" + _loc4_ + "c" + _loc3_].gotoAndStop("normal");
  137.             this["r" + _loc4_ + "c" + _loc3_]._alpha = 100;
  138.             var _loc2_ = 0;
  139.             while(_loc2_ < 4)
  140.             {
  141.                this["r" + _loc4_ + "c" + _loc3_]["ctt3_" + _loc2_]._visible = false;
  142.                _loc2_ = _loc2_ + 1;
  143.             }
  144.             _loc3_ = _loc3_ + 1;
  145.          }
  146.          _loc4_ = _loc4_ + 1;
  147.       }
  148.       _loc4_ = 0;
  149.       while(_loc4_ < 4)
  150.       {
  151.          _loc3_ = 0;
  152.          while(_loc3_ < 4)
  153.          {
  154.             this["btn" + _loc4_]["ctt3_" + _loc3_]._visible = false;
  155.             _loc3_ = _loc3_ + 1;
  156.          }
  157.          _loc4_ = _loc4_ + 1;
  158.       }
  159.    }
  160.    function normalDeg(r)
  161.    {
  162.       if(r >= 180)
  163.       {
  164.          r -= 360;
  165.       }
  166.       if(r <= -180)
  167.       {
  168.          r += 360;
  169.       }
  170.       return r;
  171.    }
  172.    function btnPrsW()
  173.    {
  174.       this._parent.prsWrong();
  175.    }
  176.    function btnPrsR()
  177.    {
  178.       this._parent.prsRight();
  179.    }
  180.    function prsWrong()
  181.    {
  182.       this.usedTimes = this.usedTimes + 1;
  183.       if(this.usedTimes > 2)
  184.       {
  185.          _global.scene.arkShape.gotoAndStop("broken");
  186.          this._visible = false;
  187.       }
  188.       _global.ctn.sndCtrl.playSound("snd_pzWrong");
  189.       this._visible = false;
  190.    }
  191.    function prsRight()
  192.    {
  193.       _global.scene.arkShape.gotoAndPlay("win");
  194.       _global.ctn.sndCtrl.playSound("snd_pzRight");
  195.       if(!_global.scene.pzArkScoreOver)
  196.       {
  197.          _global.scene.pzArkScoreOver = true;
  198.          _global.ctn.game.addScore(300,500,137,60);
  199.          _global.ctn.game.addScore(124,Math.round(412 * (1 - this.usedTimes / this.usedTimesMax)),137,65);
  200.       }
  201.       this.unloadMovie();
  202.    }
  203. }
  204.